< previous page page_202 next page >

Page 202
Embossing
An embossing filter is similar to an edge detection filter. Most of the embossing filter's kernel coefficients are zero. One coefficient on the edge of the kernel has value 1, and the opposite coefficient has value 1. The resulting image has bright highlights where the image grows darker as you move from the direction of the 1 coefficient toward the 1 coefficient. In places where the image grows lighter, the kernel produces a negative value. The results at these positions are rounded up to zero and are black like much of the rest of the image.
You can enhance the three-dimensional appearance of the result by adding 127 to each pixel's color components. Background areas that the kernel would turn black now have a medium gray value of 127. Light areas are brighter, and very dark areas stay dark.
If the image shows a dark object on a lighter background, the embossing process produces an image that looks as if a light is shining on the object from the direction of the 1 coefficient. In Figure 7.8, program Filter is applying a filter with upper left coefficient 1 and lower right coefficient 1.
Restricting an Operation Using a Mask
The Compose2 program described in Chapter 6 uses a mask image to determine which pixels it should copy from a background image and which it should copy from a foreground image. A program can use a similar technique to restrict the effects of a filter to certain parts of an image.
The mask is a grayscale image with each pixel's brightness indicating the amount by which the result pixel's value should depend on the result of the filter. Where the mask is black, the output pixel equals the result of the filter. Where the mask is white, the output pixel equals the input pixel. Where the mask is gray, the result is a weighted average of those values.
For example, if a mask pixel's value is 100, the resulting pixel's value is 100/255 times the original pixel's value plus (255 100)/255 times the result of the filter.
Example program MFilter, shown in Figure 7.9, uses this kind of mask to restrict a filter. The mask was initially produced through use of a drawing program to block out the black and white areas. It was then modified with a three-by-three low-pass filter to blur the edges between the black and white areas. This method prevents the filtered areas from having sharp edges.
0202-01.jpg
Figure 7.8
Program Filter applying an embossing filter.

 
< previous page page_202 next page >